package com.ohos.connent.modelcloud.biz.modular.pro.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.modelcloud.biz.modular.pro.param.*;
import com.ohos.connent.modelcloud.biz.modular.pro.result.BizProCategoryDetailResult;
import com.ohos.connent.modelcloud.biz.modular.pro.service.BizProCategoryService;
import com.ohos.connent.modelcloud.common.annotation.CommonLog;
import com.ohos.connent.modelcloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * 品类管理控制器
 *
 * @Author: ChenJiaHao
 * @Date: 2024/5/31 15:23
 * @Description:
 */
@Api(tags = "品类管理控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 2)
@RestController
@RequestMapping(value = "/api/v1/model/biz/pro-category")
@Validated
public class BizProCategoryController {

    @Resource
    private BizProCategoryService bizProCategoryService;

    /**
     * 新增品类
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("新增品类")
    @CommonLog("新增品类")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizProCategoryAddParam bizProCategoryAddParam) {
        return CommonResult.data(bizProCategoryService.add(bizProCategoryAddParam));
    }

    /**
     * 修改品类
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("修改品类")
    @CommonLog("修改品类")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizProCategoryEditParam bizProfileEditParam) {
        return CommonResult.data(bizProCategoryService.edit(bizProfileEditParam));
    }

    /**
     * 品类详情
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("品类详情")
    @CommonLog("品类详情")
    @GetMapping("/detail")
    public CommonResult<BizProCategoryDetailResult> detail(BizProCategoryIdParam bizProCategoryIdParam) {
        return CommonResult.data(bizProCategoryService.detail(bizProCategoryIdParam));
    }

    /**
     * 获取品类ICON文件id
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("获取品类ICON文件id")
    @CommonLog("获取品类ICON文件id")
    @PostMapping("/geFileUploadIconId")
    public CommonResult<String> geFileUploadIconId(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(bizProCategoryService.geFileUploadIconId(file));
    }

    /**
     * 下载品类ICON
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("下载品类ICON")
    @CommonLog("下载品类ICON")
    @GetMapping("/iconDownload")
    public CommonResult<String> iconDownload(BizProCategoryIdParam bizProCategoryIdParam, HttpServletResponse response) throws IOException {
        bizProCategoryService.iconDownload(bizProCategoryIdParam, response);
        return CommonResult.ok();
    }

    /**
     * 获取华为云文件下载授权URL
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("获取华为云文件下载授权URL")
    @CommonLog("获取华为云文件下载授权URL")
    @PostMapping("/file/getFileDownloadAuthUrlHUAWEI")
    public CommonResult<String> getFileDownloadAuthUrlHUAWEI(@RequestBody @Valid BizProCategoryFileIdParam bizProCategoryFileIdParam) {
        return CommonResult.data(bizProCategoryService.getFileDownloadAuthUrlHUAWEI(bizProCategoryFileIdParam));
    }

    /**
     * 根据字典id获取品类详情
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("根据字典id获取品类详情")
    @CommonLog("根据字典id获取品类详情")
    @GetMapping("/detailByDictId")
    public CommonResult<BizProCategoryDetailResult> detailByDictId(@Valid BizProCategoryDictIdParam bizProCategoryDictIdParam) {
        return CommonResult.data(bizProCategoryService.detailByDictId(bizProCategoryDictIdParam));
    }
}
